package com.wwwarehouse.common.custom_widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.wwwarehouse.common.R;

/**
 * @author feng.gao
 * @date 2015-10-21 下午7:36:35
 * @description
 */
public class BaseDialog extends Dialog implements android.view.View.OnClickListener {
    protected Context context;
    protected String[] items;
    protected IOnDialogItemListener listener;

    public BaseDialog(Context context, int style) {
        super(context, style);
    }

    public BaseDialog(Context context) {
        // TODO Auto-generated constructor stub
        super(context, R.style.commmon_transparent_window_style);
        this.context = context;
         initAttr();
    }

    private void initAttr() {
        // TODO Auto-generated method stub
//        Window w = getWindow();
//        WindowManager.LayoutParams lp = w.getAttributes();
//        lp.x = 0;
//        final int cMakeBottom = -1000;
//        lp.y = cMakeBottom;
//        lp.gravity = Gravity.BOTTOM;
//        onWindowAttributesChanged(lp);
//        setCanceledOnTouchOutside(false);
        Window win = getWindow();
        win.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        win.setAttributes(lp);
        win.setGravity(Gravity.BOTTOM);
        win.setWindowAnimations(R.style.Animation_Bottom_Rising);
    }

    public void disDialog() {
        dismiss();
    }

    public void showDialog() {
        show();
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        disDialog();
    }

    public interface IOnDialogItemListener {// 做列表选择使用

        public void onDialogItemSelected(int index);
    }
}
